﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using Leadtools;
using Leadtools.Codecs;
using MINERP.BLL.LeaderOperate;
using MINERP.ComControls;
using MINERP.LeaderOperate.Controller;
using MINERP.BLL;
using MINERP.COM;
namespace MINERP.LeaderOperate
{
    public partial class FrmLeaderOperate : FrmParent
    {
        public FrmLeaderOperate()
        {
            InitializeComponent();
            base.InitiAuthority();
        }
        private List<int> nonexistenceTechIdList = new List<int>();//非实物节点id集合
        private LeaderController _leaderControl = new LeaderController();
        private BLL.LeaderOperate.LeaderTaskBLL leaderBLL = new LeaderTaskBLL();
        private Dictionary<int, string> operates = new Dictionary<int, string>();

        private int intGroupId = 0;
        bool isTopCtrl = false;
        private DataTable tableTop = new DataTable();
        private int currSelectMember = 0;
        private int userID;

        private int MemberId;
        private Hashtable hashMembers;
        private int currStatus = 0;

        public static string stopRemark;


        private void FrmLeaderOperate_Load(object sender, EventArgs e)
        {
            nonexistenceTechIdList = leaderBLL.GetNonexistenceTechIdList();
            foreach (var item in nonexistenceTechIdList)
            {
                if (base.operates.Keys.Contains(item))
                {
                    operates.Add(base.operates.First(o => o.Key == item).Key, base.operates.First(o => o.Key == item).Value);
                }
            }
            //operates = base.operates;
            intGroupId = base.GroupId;
            userID = base.userId;
            _leaderControl.intGroupId = intGroupId;
            _leaderControl.GridControlLeaderTaskList = GridControlLeaderTaskList;

            DisPlayTop();
            DisPlayUserList();///显示组员信息    
            dateEdit_CurrFrom.Text = DateTime.Now.ToString();
            dateEdit_CurrTo.Text = DateTime.Now.ToString();
            if (leaderBLL.GetUsersByLeaderId(intGroupId).Count != 0)
            {
                DisplayWorkerInfo(leaderBLL.GetUsersByLeaderId(intGroupId)[0].userID);
            }
            else
            {
                MessageBox.Show("加载组员失败，请联系管理员添加组员信息", " 提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


            List<UserDDO> userDdos = leaderBLL.GetUsersByLeaderId(intGroupId);
            lookUpEdit_UserList.Properties.DataSource = userDdos;
            lookUpEdit_UserList.Properties.DisplayMember = "UserName";
            lookUpEdit_UserList.Properties.ValueMember = "userID";
            tabControl_workdetail.SelectedTabPageIndex = 0;
            //leaderBLL.AutoAssionTask(intGroupId,userId,operates,2);
            timerAutoAssion.Tick+=new EventHandler(timerAutoAssion_Tick);
            timerAutoAssion.Enabled = false;
            layoutControl_ON.HorizontalScroll.Visible = true;
            layoutControl_ON.VerticalScroll.Visible = true;
            layoutControl_OFF.HorizontalScroll.Visible = true;
            layoutControl_OFF.VerticalScroll.Visible = true;
        }
        //private class colorByName
        //{
        //    public string UID;
        //    public string Uname;
        //}

        /// <summary>
        /// 显示员工列表及其任务情况
        /// </summary>
        public void DisPlayUserList()
        {
            hashMembers = new Hashtable();
            this.Cursor = Cursors.WaitCursor;
            layoutControl_ON.Controls.Clear();
            layoutControl_OFF.Controls.Clear();
            List<UserDDO> users = leaderBLL.GetUsersByLeaderId(intGroupId);
            foreach (var user in users)
            {

                UTaskList ulist = new UTaskList();
                ulist.WorkerID = user.userID;
                ulist.LoginName = user.LoginName;
                ulist.WorkerName = user.UserName;
                ulist.Path = user.HeadPicPath;
                ulist.TaskMax = user.MaxTaskCount;
                ulist.Group = user.GroupName;
                ulist.Task = leaderBLL.GetTaskNumByUserId(user.userID);
                ulist.AllTask = leaderBLL.GetTaskAllNumByUserId(user.userID);
                ulist.Dock = DockStyle.Left;
                ulist.SetInfo();
                ulist.SendRush += new UTaskList.ReshTask1(RushMember);
                ulist.SendMessage += new UTaskList.PostDoubleClick(DisplayWorkerInfo);
                ulist.RushSelect += new UTaskList.ReshTask(ulist_RushSelect);
                ulist.SendClickMessage += new UTaskList.PostClick(SelectMember);
                if (user.IsOnline)
                {
                    layoutControl_ON.Controls.Add(ulist);
                }
                else
                {
                    layoutControl_OFF.Controls.Add(ulist);
                }
                hashMembers.Add(user.userID, ulist);
            }
            this.Cursor = Cursors.Default;
        }
        void SelectMember(int userid)
        {
            this.MemberId = userid;
            //layoutControl_ON.HorizontalScroll.Visible = true;
            //layoutControl_ON.VerticalScroll.Visible = true;
            //layoutControl_OFF.HorizontalScroll.Visible = true;
            //layoutControl_OFF.VerticalScroll.Visible = true;
        }

        void RushMember(int userID)
        {
            ((UTaskList)hashMembers[userID]).Task = leaderBLL.GetTaskNumByUserId(userID);
            ((UTaskList)hashMembers[userID]).AllTask = leaderBLL.GetTaskAllNumByUserId(userID);
            ((UTaskList)hashMembers[userID]).SetInfo();
             DisPlayTop();
             layoutControl_ON.HorizontalScroll.Visible = true;
             layoutControl_ON.VerticalScroll.Visible = true;
             layoutControl_OFF.HorizontalScroll.Visible = true;
             layoutControl_OFF.VerticalScroll.Visible = true;
        }
        void ulist_RushSelect()
        {
            foreach (var contol in layoutControl_ON.Controls)
            {
                //((UTaskList)contol).BorderStyle = BorderStyle.FixedSingle;
                ((UTaskList)contol).BackColor = Color.White;
                ((UTaskList)contol).splitContainer1.BackColor = Color.White;
            }
            foreach (var contol in layoutControl_OFF.Controls)
            {
                //((UTaskList)contol).BorderStyle = BorderStyle.FixedSingle;
                ((UTaskList)contol).BackColor = Color.White;
                ((UTaskList)contol).splitContainer1.BackColor = Color.White;
            }
            layoutControl_ON.HorizontalScroll.Visible = true;
            layoutControl_ON.VerticalScroll.Visible = true;
            layoutControl_OFF.HorizontalScroll.Visible = true;
            layoutControl_OFF.VerticalScroll.Visible = true;
        }
        /// <summary>
        /// 离线员工是否显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkEdit_showOff_CheckedChanged(object sender, EventArgs e)
        {
            if (checkEdit_showOff.Checked)
            {
                splitContainerControl2.PanelVisibility = SplitPanelVisibility.Both;
            }
            else
            {
                splitContainerControl2.PanelVisibility = SplitPanelVisibility.Panel1;
            }
        }
        #region 拖拽任务
        GridHitInfo downHitInfo = null;
        /// <summary>
        ///  拖拽任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridView_LeaderOpe_MouseDown(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;
            downHitInfo = null;
            GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y));

            //int[] intArrRow = gridView_LeaderOpe.GetSelectedRows();
            //ArrayList lisrProductId = new ArrayList();
            if (Control.ModifierKeys != Keys.None) return;

            if (e.Button == MouseButtons.Left && hitInfo.InRow && hitInfo.HitTest != GridHitTest.RowIndicator)
                downHitInfo = hitInfo;



        }
        public void DisPlayOrderInfo(OrderInfoDDO infoDdo)
        {
            textEdit_OederName.Text = infoDdo.OrderName;
            textEdit_Orderbarcode.Text = infoDdo.OrderBarCode;
            textEdit_ShopName.Text = infoDdo.ShopName;
            textEdit_CustomerName.Text = infoDdo.Customer;
            textEdit_orderTime.Text = infoDdo.OrderTime.ToString();
            textEdit_FetchTime.Text = infoDdo.FachTime.ToString();
            textEdit_priority.Text = infoDdo.Priority.ToString();
            textEdit_type.Text = infoDdo.Type;
            textEdit_arriveCurrTime.Text = infoDdo.ArriveDate.ToString();
            textEdit_stayTime.Text = (DateTime.Now - infoDdo.ArriveDate).Hours.ToString();
            textEdit_CurrFlow.Text = infoDdo.CurrFlow;
        }

        #endregion



        private void RushTopTaskList()
        {
            DisPlayTop();
            //combox_jiaji.SelectedIndex = -1;
            //ComboBox_status.SelectedIndex = -1;
            ComboBox_Color.SelectedIndex = 0;
            DisPlayUserList();
        }
        private void RushTopTaskList1()
        {
            DisPlayTop();
            //combox_jiaji.SelectedIndex = -1;
            //ComboBox_status.SelectedIndex = -1;
            ComboBox_Color.SelectedIndex = 0;
            //DisPlayUserList();
        }

        List<int> listIntPrioriy = new List<int>();
        List<string> ListTech = new List<string>();
        private void DisPlayTop()
        {
            try
            {
   


                List<string> listPrivrity = new List<string>();
                List<string> listStatus = new List<string>();

                
                    //, out listPrivrity, out listStatus,
                                                                   //  out listIntPrioriy, out ListTech);
                listPrivrity = leaderBLL.GetTaskPrioritylist(operates);
                listStatus = leaderBLL.GetTaskStatuslist(operates);
                ListTech = leaderBLL.GetTaskTechlist(operates);
                double unAssionAreas = leaderBLL.GetAreasByStatus(base.operates, 0);
                double AssionAreas = leaderBLL.GetAreasByStatus(base.operates, 1);
                this.labelControlUnAssion.Text = unAssionAreas.ToString("0.00");
                labelControlAssion.Text = AssionAreas.ToString("0.00");
                labelControlAllAreas.Text = (unAssionAreas + AssionAreas).ToString("0.00");

                DataTable table = leaderBLL.GetTaskByleaderIdAndOperUp(operates, tsbWorkFlow.Text, ComboBox_status.Text);
                GridControlLeaderTaskList.DataSource = table;
                GridControlLeaderTaskList.RefreshDataSource();
                this.labelControl_ViewCount.Text = table.Rows.Count.ToString();
                //gridView_LeaderOpe.ExpandAllGroups();

                this.ComboBox_Color.SelectedIndex = 2;
                tableTop = table;
                //取得数据绑定组长任务表

                ComboBox_status.ComboBox.Items.Clear();
                combox_jiaji.ComboBox.Items.Clear();
                tsbWorkFlow.Items.Clear();

                foreach (var list in listStatus)
                {
                    ComboBox_status.ComboBox.Items.Add(list);
                }
                foreach (var list in listPrivrity)
                {
                    combox_jiaji.ComboBox.Items.Add(list);
                }
                foreach (string s in ListTech)
                {
                    tsbWorkFlow.ComboBox.Items.Add(s);
                }
                if (currStatus != 0)
                {
                    ComboBox_status.SelectedIndex = currStatus;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }



        private void toolStripButton_RushTop_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            RushTopTaskList1();
            this.Cursor = Cursors.Default;
        }

        private void combox_jiaji_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (combox_jiaji.ComboBox.Items.Count > 0)
            {
                string selected = combox_jiaji.SelectedItem.ToString();
                DataTable tableTask = tableTop.Clone();
                tableTask.Clear();
                DataRow[] rows = tableTop.Select("Priority='" + selected + "'");
                foreach (DataRow row in rows)
                {
                    tableTask.ImportRow(row);
                }
                GridControlLeaderTaskList.DataSource = tableTask;
            }
        }
        private void tsbWorkFlow_DropDownClosed(object sender, EventArgs e)
        {
            if (tsbWorkFlow.ComboBox.Items.Count > 0)
            {
                if (tsbWorkFlow.SelectedItem == null)
                {
                    return;
                }

                string selected = tsbWorkFlow.SelectedItem.ToString();
                DataTable tableTask = tableTop.Clone();
                tableTask.Clear();
                DataRow[] rows;
                if (selected.Equals("全部"))
                {
                    rows = tableTop.Select();
                }
                else if (selected.Equals("当前"))
                {
                    rows = tableTop.Select("IsCurrTech='是'");
                }
                else
                {
                    rows = tableTop.Select("TechName='" + selected + "'");
                }

                foreach (DataRow row in rows)
                {
                    tableTask.ImportRow(row);
                }
                GridControlLeaderTaskList.DataSource = tableTask;
            }
        }

        private void ComboBox_status_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ComboBox_status.ComboBox.Items.Count > 0)
            {
                string selected = ComboBox_status.SelectedItem.ToString();
                DataTable tableTask = tableTop.Clone();
                tableTask.Clear();
                DataRow[] rows;
                if (selected.Equals("全部"))
                {
                    rows = tableTop.Select();
                }

                else
                {
                    rows = tableTop.Select("status='" + selected + "'");
                }

                foreach (DataRow row in rows)
                {
                    tableTask.ImportRow(row);
                }
                GridControlLeaderTaskList.DataSource = tableTask;
            }
        }

        Hashtable hashColor = new Hashtable();
        private string CurrColumn = string.Empty;
        /// <summary>
        /// 颜色排序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ComboBox_Color_SelectedIndexChanged(object sender, EventArgs e)
        {

            hashColor.Clear();
            CurrColumn = "";
            string strinitGoul = ComboBox_Color.ComboBox.SelectedItem.ToString();
            string strGoul = "";
            if (strinitGoul.Equals("商户名称"))
            {
                strGoul = "ShopName";
            }
            else if (strinitGoul.Equals("客户名称"))
            {
                strGoul = "CtmName";
            }
            else if (strinitGoul.Equals("状态"))
            {
                strGoul = "status";
            }
            else if (strinitGoul.Equals("加急级别"))
            {
                strGoul = "Priority";
            }

            Hashtable hash = new Hashtable();
            Color color = new Color();
            int red = 255;
            int green = 255;
            int blue = 255;
            var view = GridControlLeaderTaskList.Views[0];
            for (int i = 0; i < view.RowCount; i++)
            {
                if ((DataRowView)view.GetRow(i) != null)
                {
                    if (!hash.ContainsKey(((DataRowView)view.GetRow(i))[strGoul].ToString()))
                    {

                        red = (red - 15 + 255) % 255;
                        green = (green - 35 + 255) % 255;
                        blue = (blue - 55 + 255) % 255;
                        color = Color.FromArgb(red, green, blue);
                        hash.Add(((DataRowView)view.GetRow(i))[strGoul].ToString(), color);
                    }

                }
                else
                {
                    //row.DefaultCellStyle.BackColor = (Color) hash[row.Cells[strGoul].Value.ToString()];


                }
            }
            hashColor = hash;
            CurrColumn = strGoul;
            this.gridView_LeaderOpe.RefreshData();
        }

        private void gridView_LeaderOpe_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                try
                {


                    if (CurrColumn == null || CurrColumn == "")
                    {
                        return;
                    }
                    if (e.RowHandle >= 0)
                    {
                        string colunm =
                            ((DataRowView)(GridControlLeaderTaskList.Views[0].GetRow(e.RowHandle)))[CurrColumn].ToString();
                        e.Appearance.BackColor = (Color)hashColor[colunm];

                    }
                    DataRowView row = (DataRowView)gridView_LeaderOpe.GetRow(e.RowHandle);
                    //if (row["status"].ToString() == "未分配")
                    //{
                    //    //if (Convert.ToDateTime(row["PreCompleteTime"].ToString()).CompareTo(DateTime.Now) <= 0)
                    //    //{
                    //    //    e.Appearance.BackColor = Color.Red;

                    //    //}
                    //    row["ReceiveTime"] = "";
                    //    row["CompletedTime"] = "";
                    //}
                }
                catch (Exception)
                {
              

                }
            }

        }

        private void xtraTabControl_OrderPhotos_MouseHover(object sender, EventArgs e)
        {
            if (this.tabControl_workdetail.Focused == false)
            {
                this.tabControl_workdetail.Focus();
            }
        }
        List<string> shopList = new List<string>();
        List<string> customerList = new List<string>();
        /// <summary>
        /// 显示选中员工信息
        /// </summary>
        /// <param name="inWorkerID"></param>
        private void DisplayWorkerInfo(int inWorkerID)
        {
            isTopCtrl = false;
            this.MemberId = inWorkerID;
            riviewer_worker.Image = null;
            this.tabControl_workdetail.SelectedTabPageIndex = 1;
            UserDDO list = leaderBLL.GetUserById(inWorkerID);
            this.lab_workerID.Text = "工号:" + list.LoginName.ToString();
            this.lab_workerName.Text = "姓名:" + list.UserName;
            this.lab_task.Text = "当前面积::" + leaderBLL.GetTaskNumByUserId(inWorkerID);

            this.lab_maxtask.Text = "当前照片数:" + list.MaxTaskCount;
            this.lab_group.Text = "所属组:" + list.GroupName;
            currSelectMember = inWorkerID;

            ///显示所有未完成任务
            DataTable table = leaderBLL.GetUnCompleteTask(inWorkerID);
           // shopList=
           // 
           // customerList=
            BindingShopAndCustm();
            gridControl_userTask.DataSource = table;
            gridControl_userTask.RefreshDataSource();
            //RasterCodecs.Startup();
            //RasterCodecs codecs = new RasterCodecs();
            //Leadtools.RasterImage rasterimg = null;
            //Leadtools.Codecs.CodecsThumbnailOptions options = Leadtools.Codecs.CodecsThumbnailOptions.Default;
            //options.LoadStamp = false;
            //options.Resample = true;
            //riviewer_worker.AutoSize = true;
            //options.MaintainAspectRatio = true;
            //try
            //{
            //    //// RasterImage image = Image.FromFile(list.HeadPicPath);

            //    ////rasterimg = codecs.ReadThumbnail(list.HeadPicPath, options, 1);
            //    //RasterImage imgInfo = codecs.Load(list.HeadPicPath);
            //    //Rectangle rec = RasterImage.CalculatePaintModeRectangle(imgInfo.Width, imgInfo.Height, new Rectangle(0, 0, riviewer_worker.Width, riviewer_worker.Height), RasterPaintSizeMode.FitAlways, RasterPaintAlignMode.Near, RasterPaintAlignMode.Near);
            //    //codecs.Options.Jpeg.Save.StampHeight = rec.Height;
            //    //codecs.Options.Jpeg.Save.StampWidth = rec.Width;
            //    //codecs.Options.Jpeg.Save.SaveWithStamp = true;
            //    //codecs.Options.Jpeg.Save.StampBitsPerPixel = 24;
            //    //codecs.Save(imgInfo, list.HeadPicPath, RasterImageFormat.Jpeg, 0);
            //    //RasterImage img = codecs.ReadThumbnail(list.HeadPicPath, options, 1);
            //    //riviewer_worker.Image = new RasterImage(img);
            //    //riviewer_worker.AutoScroll = false;
            //    ////riviewer_worker.Image.;
            //}
            //catch (Exception ex)
            //{ }
            //finally
            //{
            //    RasterCodecs.Shutdown();
            //}
            layoutControl_ON.HorizontalScroll.Visible = true;
            layoutControl_ON.VerticalScroll.Visible = true;
            layoutControl_OFF.HorizontalScroll.Visible = true;
            layoutControl_OFF.VerticalScroll.Visible = true;

        }
        /// <summary>
        /// 绑定组员查询条件
        /// </summary>
        private void BindingShopAndCustm()
        {
            comboBoxEdit_shop.Properties.Items.Clear();
            comboBoxEdit_Customer.Properties.Items.Clear();
            foreach (string list in shopList)
            {
                comboBoxEdit_shop.Properties.Items.Add(list);
            }
            foreach (string s in customerList)
            {
                comboBoxEdit_Customer.Properties.Items.Add(s);
            }
            if (comboBoxEdit_shop.Properties.Items.Count > 0)
            {
                comboBoxEdit_shop.SelectedIndex = 0;
            }
            if (comboBoxEdit_Customer.Properties.Items.Count > 0)
            {
                comboBoxEdit_Customer.SelectedIndex = 0;
            }
        }

        private void dateEdit_CurrFrom_Click(object sender, EventArgs e)
        {
            dateEdit_CurrFrom.Text = DateTime.Now.ToString();
        }

        private void simpleButton_CurrToday_Click(object sender, EventArgs e)
        {
            DataTable tableFlow = leaderBLL.GetWorkerTaskTime(this.currSelectMember,
                                                          DateTime.Now.Date.Date,
                                                           DateTime.Now.Date.Date.AddDays(1),
                                                          comboBoxEdit_CurrDateTimeSelect.SelectedIndex
                                                          );
            gridControl_userTask.DataSource = tableFlow;
            BindingShopAndCustm();

        }

        private void dateEdit_CurrTo_Click(object sender, EventArgs e)
        {
            dateEdit_CurrTo.Text = DateTime.Now.ToString();
        }

        private void simpleButton_CurrOk_Click(object sender, EventArgs e)
        {
            DataTable tableFlow = leaderBLL.GetWorkerTask(this.currSelectMember,
                                                          Convert.ToDateTime(this.dateEdit_CurrFrom.Text),
                                                          Convert.ToDateTime(dateEdit_CurrTo.Text),
                                                          comboBoxEdit_CurrDateTimeSelect.SelectedIndex,
                                                          comboBoxEdit_UserStstus.SelectedItem.ToString()
                                                         
                                                          , out shopList,
                                                          out customerList);

            DataTable tableBind = tableFlow.Clone();
            tableBind.Clear();

            if (comboBoxEdit_shop.SelectedIndex == -1 && comboBoxEdit_Customer.SelectedIndex == -1)
            {
                this.gridControl_userTask.DataSource = tableFlow;

            }
            else if (comboBoxEdit_shop.SelectedIndex != -1 && comboBoxEdit_Customer.SelectedIndex == -1)
            {
                DataRow[] rows = tableFlow.Select("ShopName='" + comboBoxEdit_shop.SelectedItem.ToString() + "'");
                foreach (DataRow row in rows)
                {
                    tableBind.ImportRow(row);
                }
                this.gridControl_userTask.DataSource = tableBind;



            }
            else if (comboBoxEdit_shop.SelectedIndex == -1 && comboBoxEdit_Customer.SelectedIndex != -1)
            {
                DataRow[] rows = tableFlow.Select("CtmName='" + comboBoxEdit_Customer.SelectedItem.ToString() + "'");
                foreach (DataRow row in rows)
                {
                    tableBind.ImportRow(row);
                }
                this.gridControl_userTask.DataSource = tableBind;

            }
            else
            {
                DataRow[] rows = tableFlow.Select("CtmName='" + comboBoxEdit_Customer.SelectedItem.ToString() + "' and ShopName='" + comboBoxEdit_shop.SelectedItem.ToString() + "'");
                foreach (DataRow row in rows)
                {
                    tableBind.ImportRow(row);
                }
                this.gridControl_userTask.DataSource = tableBind;


            }



        }

        private void simpleButton_currYestoday_Click(object sender, EventArgs e)
        {
            DataTable tableFlow = leaderBLL.GetWorkerTaskTime(this.currSelectMember,
                                                                     DateTime.Now.Date.Date.AddDays(-1),
                                                                      DateTime.Now.Date.Date,
                                                                     comboBoxEdit_CurrDateTimeSelect.SelectedIndex,

                                                                     out shopList,
                                                                     out customerList);

            this.gridControl_userTask.DataSource = tableFlow;
            BindingShopAndCustm();
        }



        private void simpleButton_cancelTask_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            int[] rowId = gridView_task.GetSelectedRows();
            int flag = 0;
            //int aaa = Convert.ToInt32(((DataRowView)(gridView_task.GetRow(0)))["OrderProductId"]);
            foreach (int id in rowId)
            {

                if (id >= 0)
                {
                    int inWorkFlowListId = Convert.ToInt32(((DataRowView)(gridView_task.GetRow(id)))["WorkFlowListId"]);
                    string strAccept = (((DataRowView)(gridView_task.GetRow(id)))["status"]).ToString();
                    string strProductBarCode = (((DataRowView)(gridView_task.GetRow(id)))["OrderProductCode"]).ToString();
                    //int stutus = Convert.ToInt32(((DataRowView)(gridView_task.GetRow(id)))["status"]);
                    if (strAccept == "已接收")
                    {
                        if (MessageBox.Show("产品" + strProductBarCode + "组员已接收确实要回收任务吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                        {
                            leaderBLL.CancelTask(inWorkFlowListId);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    leaderBLL.CancelTask(inWorkFlowListId);
                    flag = 1;
                }
            }


            //}
            if (flag == 1)
            {
                //DisplayWorkerInfo(this.currSelectMember);
                //DisPlayUserList();
                DisPlayTop();
                RushMember(this.MemberId);
                ///显示所有未完成任务
                DataTable table = leaderBLL.GetUnCompleteTask(MemberId, out shopList, out customerList);
                BindingShopAndCustm();
                gridControl_userTask.DataSource = table;
                gridControl_userTask.RefreshDataSource();
            }
            this.Cursor = Cursors.Default;

        }
        #region
        /// <summary>
        /// 拖拽
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridView_LeaderOpe_MouseMove(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;
            if (e.Button == MouseButtons.Left && downHitInfo != null)
            {
                Size dragSize = SystemInformation.DragSize;
                Rectangle dragRect = new Rectangle(new Point(downHitInfo.HitPoint.X - dragSize.Width / 2,
                    downHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);

                if (!dragRect.Contains(new Point(e.X, e.Y)))
                {
                    DoDragDrop(GetDragData(view), DragDropEffects.All);
                    downHitInfo = null;
                }

            }
        }
        private ArrayList GetDragData(GridView view)
        {
            ArrayList result = new ArrayList();
            int[] selection = view.GetSelectedRows();

            //view.GetGroupRowValue()
            DataRowView row = (DataRowView)view.GetFocusedRow();
            //if (view.IsGroupRow(selection[0]))
            //{
            //    MessageBox.Show(selection[0].ToString());
            //}
            if (selection == null) return null;
            int count = selection.Length;


            GridColumnReadOnlyCollection columns = view.GroupedColumns;


            //List<string> arrColName = new List<string>();
            //for (int j = columns.Count - 1; j >= 0; j--)
            //{
            //    arrColName.Add(columns[j].FieldName);
            //}



            for (int i = 0; i < count; i++)
            {
                if (view.GetRowCellDisplayText(selection[i], view.Columns["status"]).ToString().Equals("未分配"))
                {
                    int id = Convert.ToInt32(view.GetRowCellDisplayText(selection[i], view.Columns["WorkFlowListId"]));
                    //if (listIntPrioriy.Count > 0)
                    //{
                    //    if (listIntPrioriy.Contains(id))
                    //    {
                    //        result.Add(id);
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("请优先分配加急级别较高的任务", "提示", MessageBoxButtons.OK, MessageBoxIcon.
                    //                                                                          Information);

                    //    }
                    //}
                    //else
                    //{
                    //    result.Add(id); 
                    //}

                    result.Add(id);
                }
                if (view.IsGroupRow(selection[i]))
                {
                    ////string endPiont = view.GetGroupRowValue(selection[i]).ToString();
                    string endPiont = view.GetGroupRowDisplayText(selection[i]).Split(':')[0];
                    int intEndPiont = 0;
                    for (int j = 0; j < columns.Count; j++)
                    {
                        if (endPiont.Equals(columns[j].Caption))
                        {
                            intEndPiont = j;
                            break;
                        }
                    }
                    List<string> arrColName = new List<string>();
                    for (int j = intEndPiont; j >= 0; j--)
                    {
                        arrColName.Add(columns[j].FieldName);
                    }


                    Hashtable hashtable = new Hashtable();
                    int intSkip = 0;
                    Hashtable check = new Hashtable();
                    for (int m = 0; m <= intEndPiont; m++)
                    {
                        string checkstr = view.GetGroupRowDisplayText(selection[i] + intSkip + m).Split(':')[0];
                        string oo = view.GetGroupRowValue(selection[i] + intSkip + m).ToString();
                        if (check.Contains(checkstr))
                        {
                            intSkip++;
                            m--;
                            continue;
                        }
                        var pp = arrColName[m].ToString();
                        hashtable.Add(pp, oo);
                        check.Add(checkstr, m);
                    }
                    string selectStr = "1=1";
                    foreach (DictionaryEntry hash in hashtable)
                    {
                        selectStr += " and " + hash.Key + "='" + hash.Value + "'";
                    }
                    DataRow[] rows = tableTop.Select(selectStr);
                    foreach (var dataRow in rows)
                    {
                        if (dataRow["status"].ToString().Equals("未分配"))
                        {
                            int id = Convert.ToInt32(dataRow["WorkFlowListId"]);
                            //if (listIntPrioriy.Count > 0)
                            //{
                            //    if (listIntPrioriy.Contains(id))
                            //    {
                            //        result.Add(id);
                            //    }
                            //}
                            //else
                            //{
                            //    result.Add(id);
                            //}

                            result.Add(id);
                        }
                    }


                }
            }
            return result;
        }
        #endregion
        [DllImport("shell32.dll ")]
        private static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);

        /// <summary>
        /// click操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 
        private int selectProductId = 0;
        private void gridView_LeaderOpe_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            try
            {
                if (e.RowHandle >= 0 && e.Column.FieldName == "orderpath")
                {
                    GridView view = sender as GridView;
                    DataRowView  dr = view.GetRow(e.RowHandle) as DataRowView;
                    string path = dr["orderpath"].ToString();  
                    ShellExecute(IntPtr.Zero, new StringBuilder("open"), new StringBuilder("explorer.exe"),
                                             new StringBuilder(path), new StringBuilder(string.Empty), 1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "确认", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        /// <summary>
        /// 显示照片
        /// </summary>
        /// <param name="strPath"></param>
        public void DisplayPhotos(int orderId)
        {
            if (orderId == 0)
            {
                return;
            }
            try
            {

                pictureViewer1.SetPhotoPath(leaderBLL.GetPhotoPath(orderId));

            }
            catch (Exception)
            {

                MessageBox.Show("未安装photoshop", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


        }

        private void gridViewFlows_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();

            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (splitContainerControl7.PanelVisibility == SplitPanelVisibility.Panel1)
            {
                this.splitContainerControl7.PanelVisibility = SplitPanelVisibility.Panel2;
                toolStripButton2.Text = "当前任务";
                SelectBindShopAndUser();
                combox_jiaji.Enabled = false;
                ComboBox_status.Enabled = false;
                ComboBox_Color.Enabled = false;

            }
            else
            {
                this.splitContainerControl7.PanelVisibility = SplitPanelVisibility.Panel1;
                toolStripButton2.Text = "查询";
                combox_jiaji.Enabled = true;
                ComboBox_status.Enabled = true;
                ComboBox_Color.Enabled = true;
            }
        }

        private void splitContainerControl1_Click(object sender, EventArgs e)
        {
            if (splitContainerControl1.PanelVisibility == SplitPanelVisibility.Both)
                splitContainerControl1.PanelVisibility = SplitPanelVisibility.Panel1;
            else
            {
                splitContainerControl1.PanelVisibility = SplitPanelVisibility.Both;
            }
        }

        public void SelectBindShopAndUser()
        {
            List<UserDDO> listUsers = leaderBLL.GetUsersByLeaderId(GroupId);
            List<ShopDDO> listShops = leaderBLL.GetShops();
            //lookUpEdit_shop.Properties.DataSource = listShops;
            //lookUpEdit_shop.Properties.DisplayMember = "shopName";
            //lookUpEdit_shop.Properties.ValueMember = "shopId";
            //lookUpEdit_User.Properties.DataSource = listUsers;
            //lookUpEdit_User.Properties.DisplayMember = "UserName";
            //lookUpEdit_User.Properties.ValueMember = "userID";
            comboBox_shop.DataSource = listShops;
            comboBox_shop.DisplayMember = "shopName";
            comboBox_shop.ValueMember = "shopId";
            comboBox_user.DataSource = listUsers;
            comboBox_user.DisplayMember = "UserName";
            comboBox_user.ValueMember = "userID";

        }

        private void checkEdit_orderDate_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkEdit_orderDate.Checked)
            {
                dateEditOrderDateFrom.Enabled = false;
                dateEditOrderDateTo.Enabled = false;
                dateEditOrderDateFrom.Text = "";
                dateEditOrderDateTo.Text = "";

            }
            else
            {
                dateEditOrderDateFrom.Enabled = true;
                dateEditOrderDateTo.Enabled = true;

                dateEditOrderDateFrom.DateTime = DateTime.Now;
                dateEditOrderDateTo.DateTime = DateTime.Now;

            }
        }

        private void checkEdit_assionDate_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkEdit_assionDate.Checked)
            {
                dateEditAssionDateFrom.Enabled = false;
                dateEditAssionDateTo.Enabled = false;
                dateEditAssionDateFrom.Text = "";
                dateEditAssionDateTo.Text = "";
            }
            else
            {
                dateEditAssionDateFrom.Enabled = true;
                dateEditAssionDateTo.Enabled = true;

                dateEditAssionDateFrom.DateTime = DateTime.Now;
                dateEditAssionDateTo.DateTime = DateTime.Now;
            }
        }

        private void checkEdit_AcceptDate_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkEdit_AcceptDate.Checked)
            {
                dateEditAcceptDateFrom.Enabled = false;
                dateEditAcceptDateTo.Enabled = false;
                dateEditAcceptDateFrom.Text = "";
                dateEditAcceptDateTo.Text = "";
            }
            else
            {
                dateEditAcceptDateFrom.Enabled = true;
                dateEditAcceptDateTo.Enabled = true;

                dateEditAcceptDateFrom.DateTime = DateTime.Now;
                dateEditAcceptDateTo.DateTime = DateTime.Now;
            }
        }

        private void checkEdit_CompleteDate_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkEdit_CompleteDate.Checked)
            {
                dateEditCompleteDateFrom.Enabled = false;
                dateEditCompleteDateTo.Enabled = false;
                dateEditCompleteDateFrom.Text = "";
                dateEditCompleteDateTo.Text = "";
            }
            else
            {
                dateEditCompleteDateFrom.Enabled = true;
                dateEditCompleteDateTo.Enabled = true;

                dateEditCompleteDateFrom.DateTime = DateTime.Now;
                dateEditCompleteDateTo.DateTime = DateTime.Now;
            }
        }
        #region//获得条件
        private string GetCondition()
        {
            string condition = "";
            if (txtOrderBarCode.Text.Trim() != "")
            {
                condition += " and Tb_OrderBag.BagCode like '%" + txtOrderBarCode.Text.Trim() + "'";
            }
            if (txtOrderName.Text.Trim() != "")
            {
                condition += " and Tb_OrderBag.BagName like  '%" + txtOrderName.Text.Trim() + "%'";
            }
            if (txtProductBarcode.Text.Trim() != "")
            {
                condition += " and orderInfo.OrderProductCode like '%" + txtProductBarcode.Text.Trim() + "'";

            }
            if (txtProductName.Text.Trim() != "")
            {
                condition += " and orderInfo.OrderProductName like '%" + txtProductName.Text.Trim() + "%'";
            }
            if (comboBox_shop.SelectedIndex != -1)
            {
                condition += " and Tb_OrderBag.Shop.shopID=" + comboBox_shop.SelectedValue.ToString();
            }
            if (textEdit_customer.Text.Trim() != "")
            {
                condition += " and orderInfo.CtmName='" + textEdit_customer.Text.Trim() + "%'";
            }
            if (comboBoxPri.SelectedIndex != -1)
            {
                condition += " and Tb_OrderBag.Priority=" + comboBoxPri.SelectedIndex + 1;
            }
            if (comboBox_user.SelectedIndex != -1)
            {
                condition += " and WorkOrderFlowList.UserId=" + comboBox_user.SelectedValue.ToString();
            }
            //if(textEdit_status.Text.Trim()!="")
            //{
            //    condition += " and WorkOrderFlowList.Status=" + textEdit_Pri.Text.Trim();
            //}
            if (checkEdit_orderDate.Checked)
            {
                condition += " and Tb_OrderBag.OrderTime > cast('" + dateEditOrderDateFrom.Text +
                             "' as System.DateTime)  and Tb_OrderBag.OrderTime< cast('" + dateEditOrderDateTo.Text +
                             "' as System.DateTime)";
            }
            if (checkEdit_assionDate.Checked)
            {
                condition += " and WorkOrderFlowList.AssignTime > cast('" + dateEditAssionDateFrom.Text +
                             "' as System.DateTime)  and WorkOrderFlowList.AssignTime< cast('" + dateEditAssionDateTo.Text +
                             "' as System.DateTime)";
            }
            if (checkEdit_AcceptDate.Checked)
            {
                condition += " and WorkOrderFlowList.ReceiveTime > cast('" + dateEditAcceptDateFrom.Text +
                                            "' as System.DateTime)  and WorkOrderFlowList.ReceiveTime< cast('" + dateEditAcceptDateTo.Text +
                                            "' as System.DateTime)";
            }
            if (checkEdit_CompleteDate.Checked)
            {
                condition += " and WorkOrderFlowList.CompletedTime > cast('" + dateEditCompleteDateFrom.Text +
                                           "' as System.DateTime)  and WorkOrderFlowList.CompletedTime< cast('" + dateEditCompleteDateTo.Text +
                                           "' as System.DateTime)";
            }
            return condition;
        }
        #endregion
        private string strCurrCondition = "";
        private int intCurrPage = 1;
        private int intPageCount = 0;//页数
        private int intCurrRecordInPage = 0;
        private void simpleButton_SelectSure_Click(object sender, EventArgs e)
        {
            strCurrCondition = "";
            intCurrPage = 1;
            intPageCount = 0;
            textEdit_currPage.Text = "1";
            //intCurrRecordInPage=
            simpleButton_FristPage.Enabled = true;
            simpleButton_previousPage.Enabled = true;
            simpleButton_NextPage.Enabled = true;
            simpleButton_lastPage.Enabled = true;
            string condition = GetCondition();
            //leaderBLL.GetHistoryList(condition, 0);
            int[] intCountArr = leaderBLL.GetPageCount(condition, operates, Convert.ToInt32(textEdit_countInpage.Text.Trim()));
            intPageCount = intCountArr[1];
            textEdit_totalCount.Text = intCountArr[0].ToString();
            if (textEdit_countInpage.Text.Trim() == "")
            {
                intCurrRecordInPage = 10;
            }
            else
            {
                intCurrRecordInPage = Convert.ToInt32(textEdit_countInpage.Text.Trim());
            }
            if (intPageCount < 2)
            {
                simpleButton_FristPage.Enabled = false;
                simpleButton_previousPage.Enabled = false;
                simpleButton_NextPage.Enabled = false;
                simpleButton_lastPage.Enabled = false;
            }
            strCurrCondition = condition;
            this.labelControl_recordCount.Text = intCountArr[1].ToString();
            gridControl_History.DataSource = leaderBLL.GetHistoryList(condition, intCurrPage, operates, intCurrRecordInPage);
        }


        private void gridView_history_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();

            }
        }

        private void GridControlLeaderTaskList_Click(object sender, EventArgs e)
        {

        }

        private void gridView_LeaderOpe_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();

            }

        }

        private void gridView_history_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            //int productId = ((MINERP.COM.RecordDDO)(gridView_history.GetRow(e.RowHandle))).OrderProductId;
            //selectProductId = productId;
            //gridControl_Flows.DataSource = leaderBLL.GetFlowHistoryList(userID, productId, operates);///显示本组流程
            //OrderInfoDDO orderinfo = leaderBLL.GetOrderInfos(productId, operates);
            ////DisPlayOrderInfo(orderinfo);  //显示定单的信息
            ////DisplayPhotos(productId);//显示照片

            //if (tabControl_workdetail.SelectedTabPage == xtraTabPage_OrderInfo)
            //{
            //    this.Cursor = Cursors.WaitCursor;
            //    DisPlayOrderInfo(orderinfo); //显示定单的信息
            //    this.Cursor = Cursors.Default;
            //}
            //if (tabControl_workdetail.SelectedTabPage == xtraTabPage_photo)
            //{
            //    this.Cursor = Cursors.WaitCursor;
            //    //DisplayPhotos(productId); //显示照片
            //    if (splitContainerphotoAndList.Panel1Collapsed)
            //    {

            //        gridControlPhoto.DataSource = leaderBLL.GetPhotosList(productId);
            //    }
            //    else
            //    {

            //        DisplayPhotos(productId);
            //    }
            //    this.Cursor = Cursors.Default;
            //}
            if (e.Column.Caption == "产品存放路径")
            {
                if (Directory.Exists(e.CellValue.ToString()))
                {
                    this.Cursor = System.Windows.Forms.Cursors.Hand;
                    ShellExecute(IntPtr.Zero, new StringBuilder("open"), new StringBuilder("explorer.exe"),
                                 new StringBuilder(e.CellValue.ToString()), new StringBuilder(string.Empty), 1);
                    this.Cursor = System.Windows.Forms.Cursors.Default;
                }
            }
        }

        private void lookUpEdit_UserList_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
        {
            if (lookUpEdit_UserList.EditValue != null)
                DisplayWorkerInfo((int)lookUpEdit_UserList.EditValue);
        }

        private void simpleButton_FristPage_Click(object sender, EventArgs e)
        {
            if (intCurrPage == 1)
            {
                return;
            }
            if (intPageCount > 1)
            {
                simpleButton_NextPage.Enabled = true;
            }
            simpleButton_previousPage.Enabled = false;
            intCurrPage = 1;
            this.textEdit_currPage.Text = intCurrPage.ToString();
            gridControl_History.DataSource = leaderBLL.GetHistoryList(this.strCurrCondition, intCurrPage, operates, intCurrRecordInPage);

        }

        private void simpleButton_previousPage_Click(object sender, EventArgs e)
        {
            intCurrPage = intCurrPage - 1;
            this.textEdit_currPage.Text = intCurrPage.ToString();
            gridControl_History.DataSource = leaderBLL.GetHistoryList(this.strCurrCondition, intCurrPage, operates, intCurrRecordInPage);
            if (intCurrPage == 1)
            {
                simpleButton_previousPage.Enabled = false;
            }
            if (intPageCount > 1)
            {
                simpleButton_NextPage.Enabled = true;
            }
        }

        private void simpleButton_NextPage_Click(object sender, EventArgs e)
        {
            intCurrPage = intCurrPage + 1;
            this.textEdit_currPage.Text = intCurrPage.ToString();
            if (intCurrPage == intPageCount)
            {
                simpleButton_NextPage.Enabled = false;
            }
            if (intPageCount > 1)
            {
                simpleButton_previousPage.Enabled = true;
            }
            gridControl_History.DataSource = leaderBLL.GetHistoryList(this.strCurrCondition, intCurrPage, operates, intCurrRecordInPage);
        }

        private void simpleButton_lastPage_Click(object sender, EventArgs e)
        {
            simpleButton_NextPage.Enabled = false;
            intCurrPage = intPageCount;
            this.textEdit_currPage.Text = intCurrPage.ToString();
            gridControl_History.DataSource = leaderBLL.GetHistoryList(this.strCurrCondition, intCurrPage, operates, intCurrRecordInPage);
            if (intPageCount > 1)
            {
                simpleButton_previousPage.Enabled = true;
            }
        }

        private void textEdit_currPage_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {

            }
        }

        private void simpleButtonuserInfoGoList_Click(object sender, EventArgs e)
        {
            this.tabControl_workdetail.SelectedTabPageIndex = 0;
        }

        private void gridView_task_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();

            }

        }

        private void simpleButton_rushZuYuan_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            DisPlayUserList();
            this.Cursor = Cursors.Default;
        }

        private void timerRushMembers_Tick(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                DisPlayUserList();
                this.Cursor = Cursors.Default;


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }

        private void pictureViewer1_Load(object sender, EventArgs e)
        {

        }

        private void simpleButton_Changer_Click(object sender, EventArgs e)
        {
            if (splitContainerphotoAndList.Panel1Collapsed)
            {
                splitContainerphotoAndList.Panel1Collapsed = false;
                splitContainerphotoAndList.Panel2Collapsed = true;
                gridControlPhoto.DataSource = leaderBLL.GetPhotosList(selectProductId);
                DisplayPhotos(selectProductId);
            }
            else
            {
                splitContainerphotoAndList.Panel1Collapsed = true;
                splitContainerphotoAndList.Panel2Collapsed = false;
                gridControlPhoto.DataSource = leaderBLL.GetPhotosList(selectProductId);
                DisplayPhotos(selectProductId);
            }
        }

        private void dateEdit_CurrFrom_Properties_VistaTimeProperties_EditValueChanged(object sender, EventArgs e)
        {
            dateEdit_CurrFrom.ClosePopup();
        }

        private void dateEdit_CurrTo_Properties_VistaTimeProperties_EditValueChanged(object sender, EventArgs e)
        {
            dateEdit_CurrTo.ClosePopup();
        }

        private void FrmLeaderOperate_FormClosing(object sender, FormClosingEventArgs e)
        {
            MINERP.COM.Logoff.ShowMainFrm();
        }

        private void ComboBox_status_DropDownClosed(object sender, EventArgs e)
        {
            currStatus = ComboBox_status.SelectedIndex;
        }

        private void gridView_LeaderOpe_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle > 0)
            {
                int productId =
                    Convert.ToInt32(((DataRowView)(gridView_LeaderOpe.GetRow(e.FocusedRowHandle)))["OrderProductId"]);
                selectProductId = productId;
                if (tabControl_workdetail.SelectedTabPageIndex == 2)
                {
                    gridControl_Flows.DataSource = leaderBLL.GetFlowHistoryList(userID, productId, operates); ///显示本组流程
                    OrderInfoDDO orderinfo = leaderBLL.GetOrderInfos(productId, operates);
                    if (tabControl_workdetail.SelectedTabPage == xtraTabPage_OrderInfo)
                    {
                        this.Cursor = Cursors.WaitCursor;
                        DisPlayOrderInfo(orderinfo); //显示定单的信息
                        this.Cursor = Cursors.Default;
                    }
                }

                if (tabControl_workdetail.SelectedTabPage == xtraTabPage_photo)
                {
                    this.Cursor = Cursors.WaitCursor;
                    //DisplayPhotos(productId); //显示照片
                    if (splitContainerphotoAndList.Panel1Collapsed)
                    {

                        gridControlPhoto.DataSource = leaderBLL.GetPhotosList(selectProductId);
                    }
                    else
                    {

                        DisplayPhotos(selectProductId);
                    }
                    this.Cursor = Cursors.Default;
                }
            }
        }

        private void gridView_history_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle > -1)
            {
                int productId = ((MINERP.COM.RecordDDO)(gridView_history.GetRow(e.FocusedRowHandle))).OrderProductId;
                selectProductId = productId;


                //DisPlayOrderInfo(orderinfo);  //显示定单的信息
                //DisplayPhotos(productId);//显示照片

                if (tabControl_workdetail.SelectedTabPage == xtraTabPage_OrderInfo)
                {
                    gridControl_Flows.DataSource = leaderBLL.GetFlowHistoryList(userID, productId, operates); ///显示本组流程
                    OrderInfoDDO orderinfo = leaderBLL.GetOrderInfos(productId, operates);
                    this.Cursor = Cursors.WaitCursor;
                    DisPlayOrderInfo(orderinfo); //显示定单的信息
                    this.Cursor = Cursors.Default;
                }
                if (tabControl_workdetail.SelectedTabPage == xtraTabPage_photo)
                {
                    this.Cursor = Cursors.WaitCursor;
                    //DisplayPhotos(productId); //显示照片
                    if (splitContainerphotoAndList.Panel1Collapsed)
                    {

                        gridControlPhoto.DataSource = leaderBLL.GetPhotosList(productId);
                    }
                    else
                    {

                        DisplayPhotos(productId);
                    }
                    this.Cursor = Cursors.Default;
                }
            }
        }

        private void timer_rushTask_Tick(object sender, EventArgs e)
        {
            try
            {
                RushTopTaskList();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private bool AutoAssionFalg = false;
        private bool isBack = false;
        private FrmAutoAssion frmAutoAssion = new FrmAutoAssion();
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            frmAutoAssion = new FrmAutoAssion(AutoAssionFalg);
            frmAutoAssion.leader = this;

            frmAutoAssion.StartTimer += new FrmAutoAssion.TimerControl(frmAutoAssion_StartTimer);
            frmAutoAssion.EndtTimer += new FrmAutoAssion.TimerControl(frmAutoAssion_EndtTimer);

            frmAutoAssion.ShowDialog();
        }


        Timer timerAutoAssion=new Timer();
        
        void frmAutoAssion_EndtTimer(bool isCallBack)
        {
           
           // timerAssionTask.Interval = Convert.ToInt32(Convert.ToDouble(Properties.Settings.Default.AutoAssionTaskTimeSpan) * 60000);
            timerAutoAssion.Interval = Convert.ToInt32(Convert.ToDouble(Properties.Settings.Default.AutoAssionTaskTimeSpan) * 60000);
            AutoAssionFalg = false;
            //timerAssionTask.Stop();
            timerAutoAssion.Stop();
            //timerAssionTask.Enabled = false;
            timerAutoAssion.Enabled = false;
            timer_rushTask.Enabled = true;
            //timerRushMembers.Enabled = true;
        }

        void frmAutoAssion_StartTimer(bool isCallBack)
        {
           // timerAssionTask.Enabled = true;
            timerAutoAssion.Enabled = true;
            AutoAssionFalg = true;
            //timerAssionTask.Interval = Convert.ToInt32(Convert.ToDouble(Properties.Settings.Default.AutoAssionTaskTimeSpan) * 60000);
            timerAutoAssion.Interval = Convert.ToInt32(Convert.ToDouble(Properties.Settings.Default.AutoAssionTaskTimeSpan) * 60000);

            //timerAssionTask.Start();
            timerAutoAssion.Start();
            timer_rushTask.Enabled = false;
            //timerRushMembers.Enabled = false;
        }
        int count = 0;///累计分配数量
        private void timerAssionTask_Tick(object sender, EventArgs e)
        {
            try
            {
                if (Properties.Settings.Default.IsCallBack == true)
                {
                    leaderBLL.CallBackTask(base.GroupId);
                }

                count += leaderBLL.AutoAssionTaskBll2(this.GroupId, base.userId, base.operates, Convert.ToInt32(Properties.Settings.Default.AutoAssionTaskNum), Properties.Settings.Default.IsAssionToLeader);
                frmAutoAssion.labelControl_Num.Text = count + "";

            }
            catch (Exception exception)
            {

                MessageBox.Show("自动分配任务异常，请手动分配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
       // int count = 0;///累计分配数量
        private void timerAutoAssion_Tick(object sender, EventArgs e)
        {
            try
            {
                if (Properties.Settings.Default.IsCallBack == true)
                {
                    leaderBLL.CallBackTask(base.GroupId);
                }

                count += leaderBLL.AutoAssionTaskBll2(this.GroupId, base.GroupId, base.operates, Convert.ToInt32(Properties.Settings.Default.AutoAssionTaskNum), Properties.Settings.Default.IsAssionToLeader);
                frmAutoAssion.labelControl_Num.Text = count + "";

            }
            catch (Exception exception)
            {

                MessageBox.Show("自动分配任务异常，请手动分配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }

        private void toolStripButtonCallBackTask_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == MessageBox.Show("确定要回收所有组员未完成任务吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
            {
                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    leaderBLL.CallBackTask(base.GroupId);
                   
                    RushTopTaskList1();
                    this.Cursor = Cursors.Default;
                }
                catch (Exception ex)
                {

                    MessageBox.Show("回收任务失败，请重新尝试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

        }

        private void gridView_task_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            if (e.RowHandle > -1)
            {
                if (e.Column.Caption == "产品路径")
                {
                    if (Directory.Exists(e.CellValue.ToString()))
                    {
                        this.Cursor = System.Windows.Forms.Cursors.Hand;
                        ShellExecute(IntPtr.Zero, new StringBuilder("open"), new StringBuilder("explorer.exe"),
                                     new StringBuilder(e.CellValue.ToString()), new StringBuilder(string.Empty), 1);
                        this.Cursor = System.Windows.Forms.Cursors.Default;
                    }
                }
            }
        }

        private void simpleButtonCancel_Click(object sender, EventArgs e)
        {
            txtOrderBarCode.Text = "";
            txtOrderName.Text = "";
            txtProductBarcode.Text = "";
            textEdit_customer.Text = "";
            comboBox_shop.Text = "";
            textEdit_customer.Text = "";
            comboBoxPri.Text = "";
            comboBox_user.Text = "";
            checkEdit_orderDate.Checked = false;
            checkEdit_assionDate.Checked = false;
            checkEdit_AcceptDate.Checked = false;
            checkEdit_CompleteDate.Checked = false;
            dateEditOrderDateFrom.Text = "";
            dateEditOrderDateTo.Text = "";
            dateEditOrderDateFrom.Text = "";
            dateEditOrderDateTo.Text = "";
            dateEditAcceptDateFrom.Text = "";
            dateEditAcceptDateTo.Text = "";
            dateEditAssionDateFrom.Text = "";
            dateEditAssionDateTo.Text = "";
            dateEditCompleteDateFrom.Text = "";
            dateEditCompleteDateTo.Text = "";
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            //开返工
            if (gridView_LeaderOpe.GetFocusedRow() != null)
            {
                FrmSelectBackTch frm = new FrmSelectBackTch();
                frm.Techs = base.operates;

                frm.OrderInfoId = Convert.ToInt32(((DataRowView)(gridView_LeaderOpe.GetFocusedRow()))["OrderProductId"]);
                frm.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择某一记录!");
            }
        }

        private void tabControl_workdetail_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            if (tabControl_workdetail.SelectedTabPageIndex == 1)
            {
                if (MemberId != 0)
                {
                    DisplayWorkerInfo(this.MemberId);
                }
                else
                {
                    MessageBox.Show("请选中组员!");
                }
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            frmMain frm=MINERP.ComControls.frmMain.GetInstance(base.userId);
            frm.Show();
          
        }

        private void splitContainerControl2_Scroll(object sender, XtraScrollEventArgs e)
        {
            //layoutControl_ON.HorizontalScroll.Visible = true;
            //layoutControl_ON.VerticalScroll.Visible = true;
            //layoutControl_OFF.HorizontalScroll.Visible = true;
            //layoutControl_OFF.VerticalScroll.Visible = true;
        }

        private void splitContainerControl2_SplitterMoved(object sender, EventArgs e)
        {
            layoutControl_ON.HorizontalScroll.Visible = true;
            layoutControl_ON.VerticalScroll.Visible = true;
            layoutControl_OFF.HorizontalScroll.Visible = true;
            layoutControl_OFF.VerticalScroll.Visible = true;
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            FrmGroupEmployment frm = new FrmGroupEmployment(userId);
            frm.Show();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            List<int> orderProductIdList = new List<int>();
            List<int> rowhandles = gridView_LeaderOpe.GetSelectedRows().ToList();
            if (rowhandles.Count > 0)
            {
         
                foreach (var item in rowhandles)
                {
                    int oid = Convert.ToInt32(((DataRowView)(gridView_LeaderOpe.GetRow(item)))["OrderProductId"]);
                    orderProductIdList.Add(oid);
                }
                FrmPriority frm = new FrmPriority();
                frm.orderproductIdList = orderProductIdList;
                frm.ShowDialog(this);
                DisPlayTop();
            }
            else
            {
                MessageBox.Show("请选择要加急的产品！","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        
        }

        private void tsbtnPause_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == MessageBox.Show("您确定要暂停生产该产品吗？", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
            {
                try
                {
                    int orderProductId = Convert.ToInt32(((DataRowView)(gridView_LeaderOpe.GetFocusedRow()))["OrderProductId"]);
                    FrmStopRemark frm = new FrmStopRemark();
                    frm.ShowDialog();
                    leaderBLL.PauseOrderProduct(orderProductId, 0, stopRemark, userId);
                    RushTopTaskList1();

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    stopRemark = "";//清空备注
                }
            }
        }







        //private void gridView_LeaderOpe_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        //{
        //    if(e.RowHandle>0)
        //    {
        //        if (e.Column.FieldName.Equals("ReceiveTime") || e.Column.FieldName.Equals("AssignTime"))
        //        {


        //        }
        //    }
        //}

        //private void gridView_LeaderOpe_RowCellStyle(object sender, RowCellStyleEventArgs e)
        //{
        //    if(e.RowHandle>0)
        //    {
        //        if (e.Column.FieldName.Equals("ReceiveTime") || e.Column.FieldName.Equals("AssignTime"))
        //        {
        //            if(e.Column.c)

        //        }
        //    }
        //}

    }
}
